﻿/**
 ** @作者:	   王桂龙 QQ731513122
 ** @日期:	   2019.12.6
 ** @简介:     进度条，有待丰富        
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace BHXJDOTNET.NEW
{
    public partial class BHXJProgressBar : BHXJContainer, IBHXJZOOM
    {
        /// <summary>
        /// 水平颜色组
        /// </summary>
        //static Color[] horizontalcolors = 
        //    {  
        //        Color.FromArgb(0xff,0x00,0x90,0x00),  
        //        Color.FromArgb(0xff,0x00,0xe0,0x00),

                
        //        Color.FromArgb(0xff,0x00,0xe0,0x00),
        //        Color.FromArgb(0xff,0x00,0x90,0x00)     
        //    };
        static Color[] horizontalcolors = 
            {  
                Color.FromArgb(0xff,0x00,0xAF,0x00),  
                Color.FromArgb(0xff,0x00,0xFF,0x00),

                
                Color.FromArgb(0xff,0x00,0xFF,0x00),
                Color.FromArgb(0xff,0x00,0xAF,0x00)     
            };
        /// <summary>
        /// 水平位置组
        /// </summary>
        static float[] horizontalpositions = { 0.0f, 0.1f, 0.9f, 1.0f };

        /// <summary>
        /// 垂直颜色组
        /// </summary>
        //static Color[] verticalcolors = 
        //    {  
        //        Color.FromArgb(176,0xAF,0xFF,0xAF),  
        //        Color.FromArgb(80,0x00,0xAF,0x00),  

        //        Color.FromArgb(00,0x00,0xFF,0x00),   
        //        Color.FromArgb(64,0x00,0xFF,0x00)      
        //    };
        static Color[] verticalcolors = 
            {  
                Color.FromArgb(176,0xE0,0xFF,0xE0),  
                Color.FromArgb(80,0x90,0xAF,0x90),  

                Color.FromArgb(00,0xE0,0xFF,0xE0),   
                Color.FromArgb(64,0xE0,0xFF,0xE0)      
            };
        /// <summary>
        /// 垂直位置组
        /// </summary>
        static float[] verticalpositions = { 0f, 0.3f, 0.85f, 1f };




        /// <summary>
        /// 水平colorblend
        /// </summary>
        ColorBlend colorBlendH = new ColorBlend(4);

        /// <summary>
        /// 垂直方向colorBlend
        /// </summary>
        ColorBlend colorBlendV = new ColorBlend(4);

        /// <summary>
        /// 百分比
        /// </summary>
        private double _percent = 50;
        /// <summary>
        /// 百分比
        /// </summary>
        public double percent
        {
            get { return _percent; }
            set
            {
                if (this._percent != value)
                {
                    this._percent = value;
                    this.changed = true;
                }
            }

        }

        /// <summary>
        /// 变化标志
        /// </summary>
        private bool changed = false;

        private Timer refreshTimer = new Timer();

        public BHXJProgressBar()
        {
            InitializeComponent();

            //设置初始
            this.IniSize = this.Size;
            this.IniFont = this.Font;
            this.IniLocation = this.BHXJGetIniLocationInDesignMode();

            refreshTimer.Interval = 50;
            refreshTimer.Tick+=new EventHandler(refreshTimer_Tick);
            refreshTimer.Start();

            colorBlendH.Colors = horizontalcolors;
            colorBlendH.Positions = horizontalpositions;

            colorBlendV.Colors = verticalcolors;
            colorBlendV.Positions = verticalpositions;
        }

        /// <summary>
        /// 重载paint函数
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics gs = e.Graphics;
            gs.SmoothingMode = SmoothingMode.None;

            //水平方向
            int length = (this.percent > 100) ? this.Width : (int)((this.percent * this.Width) / 100);
            if (length > 0)
            {
                LinearGradientBrush lgbL = new LinearGradientBrush(new Point(0, 0), new Point(length, 0), Color.White, Color.Black);
                lgbL.InterpolationColors = colorBlendH;
                gs.FillRectangle(lgbL, 0, 0, length, this.Height);
            }
            if (this.percent < 100)
            {
                gs.SmoothingMode = SmoothingMode.AntiAlias;
                Pen backpen = new Pen(this.BackColor, 3);
                gs.DrawArc(backpen, length - 6, -2, 7, 7, 0, -90);
                gs.DrawArc(backpen, length - 6, this.Height - 6, 7, 7, 0, 90);
            }

            

            gs.SmoothingMode = SmoothingMode.None;
            //垂直方向
            LinearGradientBrush lgbV = new LinearGradientBrush(new Point(0, 0), new Point(0, this.Height), Color.White, Color.Black);
            lgbV.GammaCorrection = true;
            lgbV.InterpolationColors = colorBlendV;
            gs.FillRectangle(lgbV, this.ClientRectangle);

            {
                //圆角
                gs.SmoothingMode = SmoothingMode.AntiAlias;
                Pen backpen = new Pen(this.BackColor, 3);
                gs.DrawArc(backpen, -2, -2, 7, 7, -90, -90);
                gs.DrawArc(backpen, this.Width - 6, -2, 7, 7, 0, -90);
                gs.DrawArc(backpen, -2, this.Height - 6, 7, 7, 90, 90);
                gs.DrawArc(backpen, this.Width - 6, this.Height - 6, 7, 7, 0, 90);
            }
        }
        public void refreshTimer_Tick(object sender, EventArgs e)
        {
            if (this.changed)
                this.Invalidate();
        }
    }
}
